package com.year_23.april;

import java.util.Arrays;

/**
 * @author: jsh
 * @create: 2023/4/25 20:54
 * @Description: 2418. 按身高排序
 * @FileName: Day25
 * @History:
 * @自定义内容：
 */
public class Day25 {

    public static void main(String[] args) {
        int[] heights ={17233,32521,14087,42738,46669,65662,43204,8224};
        String[] names = {"IEO","Sgizfdfrims","QTASHKQ","Vk","RPJOFYZUBFSIYp","EPCFFt","VOYGWWNCf","WSpmqvb"};

        sortPeople(names, heights);
    }
    public String[] sortPeople2(String[] names, int[] heights) {
        int n = names.length;
        Integer[] indices = new Integer[n];
        for (int i = 0; i < n; i++) {
            indices[i] = i;
        }
        Arrays.sort(indices, (a, b) -> heights[b] - heights[a]);
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = names[indices[i]];
        }
        return res;
    }

    public static String[] sortPeople(String[] names, int[] heights) {

        int length = heights.length;
        int[] arr = new int[length];
        for (int i = 0; i < length; i++) {
            arr[i]=i;
        }
        for (int i = 0; i < length; i++) {
            for (int j = i; j < length; j++) {
                if (heights[arr[i]] < heights[arr[j]]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }



        }
        String[] strings = new String[length];
        for (int i = 0; i < length; i++) {
            strings[i] = names[arr[i]];
        }
        return strings;
    }

}
